package com.zsck.openali;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;

import com.zsck.openali.service.AccessibilityServiceMonitor;
import com.zsck.openali.service.AlipayForestMonitor;
import com.zsck.openali.util.AccessibilitUtil;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
        initService();
    }

    private void initService() {
        Intent mIntent = new Intent(this, AccessibilityServiceMonitor.class);
        startService(mIntent);
    }

    private void initView() {
        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlipayForestMonitor.startAlipay(MainActivity.this);
//                Intent intent = new Intent(MainActivity.this, AccessibilityServiceMonitor.class);
//                intent.setAction(AccessibilityServiceMonitor.ACTION_UPDATE_SWITCH);
//                MainActivity.this.startService(intent);
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (AccessibilitUtil.isAccessibilitySettingsOn(this, AccessibilityServiceMonitor.class.getCanonicalName())) {

        } else {
            Intent mIntent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
            startActivity(mIntent);
        }
    }
}